package com.github.chirspan.xaas.auth.integration.authenticator;

import com.github.chirspan.xaas.auth.integration.IntegrationAuthentication;
import com.github.chirspan.xaas.security.service.AuthUserDetail;
import org.springframework.stereotype.Component;

/**
 * *******description*******
 * 微信小程序登录认证
 * *************************
 *
 * @author chenpan
 * @date 2020/2/19 13:23
 */
@Component
public class WXMiniIntegrationAuthenticator extends AbstractPreparableIntegrationAuthenticator {

    private final static String WXMINI_AUTH_TYPE = "wx-mini";


    /**
     * 处理集成认证
     *
     * @param integrationAuthentication
     * @return
     */
    @Override
    public AuthUserDetail authenticate(IntegrationAuthentication integrationAuthentication) throws Exception {
        String code = integrationAuthentication.getAuthParameter("code");
        //1.获取openId

        //2.根据openId查询内部用户信息

        //3.用户不存在，自动注册

        return null;
    }

    /**
     * 进行预处理
     *
     * @param integrationAuthentication
     */
    @Override
    public void prepare(IntegrationAuthentication integrationAuthentication) {

    }

    /**
     * 判断是否支持集成认证类型
     *
     * @param integrationAuthentication
     * @return
     */
    @Override
    public boolean support(IntegrationAuthentication integrationAuthentication) {
        return WXMINI_AUTH_TYPE.equalsIgnoreCase(integrationAuthentication.getAuthType());
    }

    /**
     * 认证结束后执行
     *
     * @param integrationAuthentication
     */
    @Override
    public void complete(IntegrationAuthentication integrationAuthentication) {

    }
}
